package com.itheima_03;

import java.util.Scanner;

/*
    已知一个数组，键盘录入一个数据，查找该数据在数组中的索引，并在控制台输出索引值
*/
public class GetIndex {
    public static void main(String[] args) {
        int[] arr = {19, 28, 37, 46, 50};
        System.out.println("已知数组为：");
        for (int i = 0; i < arr.length; i++) {
            if (i == arr.length - 1) {
                System.out.println(arr[i]);
            } else {
                System.out.print(arr[i] + "\t");
            }
        }
        int index = -1;
        Scanner sc = new Scanner(System.in);
        System.out.println("请输入一个该数组中的数：");
        int num = sc.nextInt();
        for (int i = 0; i < arr.length; i++) {
            if (num == arr[i]) {
                index = i;
                break;
            }
        }
        if (index == -1) {
            System.out.println("数组中不存在" + num);
        } else {
            System.out.println(num + "\t在数组中对应的索引值是\t" + index);
        }

    }
}
